package com.neusoft.yuejian_01.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.javabean.NewsBean;
import com.neusoft.yuejian_01.viewHolder.NewslistHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by MARIA on 2017/10/13.
 */

public class NewslistAdapter extends RecyclerView.Adapter{



    private List<NewsBean>  news = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;//使用了LayoutInflater来载入布局界面
    public NewslistAdapter(Context context, List<NewsBean> news) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this. news.addAll(news);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=layoutInflater.inflate(R.layout.item_my_news,parent,false);
        NewslistHolder holder=new NewslistHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {


        NewslistHolder  newslistHolder=(NewslistHolder) holder;
        final NewsBean newsBean = news.get(position);


        String newstime=newsBean.getI_createtime();
        String newsinfo=newsBean.getI_info();

        newslistHolder. newsLnfo.setText(newsinfo);
        newslistHolder.newsTime.setText(newstime);


    }

    @Override
    public int getItemCount() {
        return news.size();
    }
}